package com.example.roomandrlivedata.database;

import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

import com.example.roomandrlivedata.bean.Student;


/**
 * @author: njb
 * @date: 2020/8/28 0028 0:19
 * @desc:学生数据库
 */
@Database(entities = {Student.class}, exportSchema = false, version = 1)
public abstract class MyDatabase extends RoomDatabase {
    private static final String DATABASE_NAME = "student_db";

    private static MyDatabase databaseInstance;

    public static synchronized MyDatabase getInstance(Context context) {
        if (databaseInstance == null) {
            databaseInstance = Room
                    .databaseBuilder(context.getApplicationContext(), MyDatabase.class, DATABASE_NAME)
                    .build();
        }
        return databaseInstance;
    }

    public abstract StudentDao studentDao();
}
